<template>
  <div class="community views-container">
    <div class="wlm-table">
      <div class="wlm-table-hearder-btn">
        <router-link tag="span" to="/application/supplierManagementAdd">
          <el-button size="small" type="primary">添加供应商</el-button>
        </router-link>
      </div>
      <div class="wlm-table-header">
        <el-form :model="tableFormatData.supplyierList.files" size="small" label-width="100px" class="retail-form" label-position="right">
            <el-form-item label="供应商名称：" class="search">
              <el-input v-model="tableFormatData.supplyierList.files.name" placeholder="请输入供应商名称" style="width:170px;"></el-input>
            </el-form-item>
            <el-form-item label="供应商联系人：" class="search">
              <el-input v-model="tableFormatData.supplyierList.files.key" placeholder="请输入联系人/手机号" style="width:170px;"></el-input>
            </el-form-item>
           <el-form-item label="" class="filter-btns">
              <el-button v-waves type="primary" @click="filesSerch">筛选</el-button>
              <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
            </el-form-item>

        </el-form>
      </div>
      <div class="wlm-table-content">
        <el-table :ref="tableFormatData.supplyierList.key" :data="tableFormatData.supplyierList.tableData" @selection-change="handleSelectionChange" style="width: 100%">
          <!-- <el-table-column type="selection" width="55">
                </el-table-column> -->

          <el-table-column prop="name" label="供应商名称">
          </el-table-column>
          <el-table-column label="供应商logo">
            <template slot-scope="scope">
              <img height="50" width="50" :src="scope.row.logo.length?scope.row.logo[0].file_path ?scope.row.logo[0].file_path :'' :''" alt="这是图片">
            </template>
          </el-table-column>
          <el-table-column prop="user_name" label="联系人">
          </el-table-column>
          <el-table-column prop="phone" label="联系手机">
          </el-table-column>
          <el-table-column prop="goods_num" label="商品数量">
          </el-table-column>
          <el-table-column prop="status" label="状态">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.status" :active-value='1' :inactive-value='2' @change="changeTableItem({s_id:scope.row.s_id,status:scope.row.status},tableFormatData.supplyierList.change.status)">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="添加时间">
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <div class="operation-group">
                <router-link class="wlm-text" tag="span" :to="{path:'/application/supplierManagementAdd', query:{s_id:scope.row.s_id}}">
                  <el-button type="text">编辑</el-button>
                </router-link>
                <div class="btn-line"></div>
                <el-button class="wlm-text" type="text" @click="validate({number:scope.row.goods_num,s_id:scope.row.s_id})">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-e flex-align-c">
          <el-pagination
:disabled="!hasTableData"
@size-change="listPageChange"
           @current-change="listPageChange"
:current-page.sync="tableFormatData.supplyierList.pagination.page"
           :page-sizes="tableFormatData.supplyierList.pagination.pagesizes"
           :page-size.sync="tableFormatData.supplyierList.pagination.list_rows"
layout="total, sizes, prev, pager, next, jumper"
:total="hasTableData?tableFormatData.supplyierList.pagination.total : 0">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSupplierList, delSupplier, changeStatus } from '@/api/commityBuy'

import waves from '@/directive/waves' // Waves directive
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'Community',
  components: {

  },
  directives: {
    waves
  },
  data() {
    return {
      tableFormatData: {
        current: 'supplyierList',
        supplyierList: {
          key: 'supplyierList',
          api: {
            getList: getSupplierList,
            delList: delSupplier
          },
          tableData: [],
          rowId: 's_id',
          files: {
            name: '',
            key: '',
            s_id: [],
            checkall: '0',
            redirect: 's_id'
          },
          change: {
            status: {
              key: 'status',
              api: changeStatus
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    validate({ number, s_id }) {
      if (number) {
        this.$message.warning('该供应商有关联的商品无法删除')
      } else {
        this.delTableItem(s_id)
      }
    }

  }
}
</script>

